package com.lxyk.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName GateWayConfig
 * @Description TODO
 * @Author ZJL
 * @Date 2022/5/9 1:54
 * @Version 1.0
 **/
@Configuration
public class GateWayConfig {
    //配置了一个id为route-name的路由规则，当访问地址：http://localhost:9527/guonei时会转发到地址：news.baidu.com/guonei
    //RouteLocator:路由
    //RouteLocatorBuilder:路由构建器

   /* @Resource
    private RouteLocatorBuilder routeLocatorBuilder;*/

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();

        routes.route("path_rote_lxyk",
                r -> r.path("/guonei")
                        .uri("http://news.baidu.com/guonei")).build();

        return routes.build();
    }
}
